/* 
 * File:   UserMessages.cpp
 * Author: Lance
 * 
 * Created on October 1, 2012, 10:54 AM
 */

#include "UserMessages.h"

UserMessages* UserMessages::instance = NULL;

UserMessages::UserMessages() {
	sem_init(&messagesUnlocked, 0, 1);
}

UserMessages * UserMessages::getSingleton()
{
	if(!instance)
	{
		instance = new UserMessages();
	}
	return instance;
}

UserMessages::UserMessages(const UserMessages& orig) {
}

UserMessages::~UserMessages() {
}

vector<Message> UserMessages::getUsersMessages(string user)
{
	sem_wait(&messagesUnlocked);
	vector<Message> messages = userMessages[user];
	sem_post(&messagesUnlocked);
	return messages;
}

void UserMessages::putUserMessage(string user, Message userMessage)
{
	sem_wait(&messagesUnlocked);
	userMessages[user].push_back(userMessage);
	sem_post(&messagesUnlocked);
}

